package grammar.Others;

import java.util.ArrayList;
import java.util.List;

/**
 * @Project ：learn_java
 * @File ：test02.java
 * @IDE ：IntelliJ IDEA
 * @Author ：自由如风间
 * @Date ：2025/4/9 22:11
 * @Description ：For study.
 */

public class test02 {

    public static void main(String[] args) {
        List<String> list = new ArrayList<>(2);
        list.add("mei");
        list.add("guan");

        // toArray默认返回类型是Object
        Object[] array1 = list.toArray();
        System.out.println("Object:");
        for (Object o : array1) {
            System.out.println(o);
        }

        String[] strings = new String[list.size()];
        // 指定toArray内容
        String[] array2 = list.toArray(strings);
        System.out.println("String:");
        for (String s : array2) {
            System.out.println(s);
        }
    }
}
